﻿namespace rili
{
    internal class Program
    {
        static void Main(string[] args)
        {
            const int MonthLength = 35;
            const int MonthHeight = 8;
            const int dayLength = 4;
            //确定初始日期
            DateTime theDay = new DateTime(2022, 1, 1);
            //确定初始位置
            int x = 0, y = 0, theWeekdayofOne = 0;
            //输出日期
            do
            {
                if (theDay.Day == 1)
                {
                    x = ((theDay.Month - 1) % 3) * MonthLength;
                    y = (theDay.Month - 1) / 3 * MonthHeight;
                    Console.SetCursorPosition(x, y);
                    Console.Write("{0,12}月", theDay.Month);
                    Console.SetCursorPosition(x, y + 1);
                    Console.Write("日  一  二  三  四  五  六");
                    //确定每月一号的星期
                    theWeekdayofOne = Convert.ToInt32(theDay.DayOfWeek);
                }
                int dayofweek = Convert.ToInt32(theDay.DayOfWeek);
                Console.SetCursorPosition(x + dayofweek * dayLength, y + (int)Math.Ceiling((theDay.Day - 7 + theWeekdayofOne) / 7.0) + 2);
                Console.Write("{0,2}", theDay.Day);
                theDay = theDay.AddDays(1);
            }
            while (theDay.Year == 2022);
            Console.ReadKey();
        }
    }
}